package com.sgb.kjwl.view.widget;

import android.content.Context;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.sgb.businessmodule.entity.PickFilterEntity;
import com.sgb.businessmodule.view.ui.adapter.PopularFilterAdapter;
import com.sgb.kjwl.R;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.dialog.PopViewHolder;
import com.swgk.core.recyclerview.adapter.AdapterOnItemClick;

import java.util.List;

/**
 * 单方框网格式选择器
 * LiWei 2021/12/10
 */
public class BoxSelectorWindow extends BasePopWindow {

    private BoxOnClickListener listener;
    private PopularFilterAdapter adapter;

    public BoxSelectorWindow(Context context) {
        super(context);
    }

    @Override
    protected int popLayout() {
        return R.layout.window_box_selector;
    }

    @Override
    protected void initView(PopViewHolder holder) {
        RecyclerView recycler = holder.getPop().findViewById(R.id.rlv_list);

        adapter = new PopularFilterAdapter(mContext, com.sgb.businessmodule.R.layout.item_popular_filter, null);
        adapter.setItemSelect(true);
        recycler.setLayoutManager(new GridLayoutManager(mContext, 4));
        recycler.setAdapter(adapter);
        adapter.setOnItemClick(new AdapterOnItemClick<PickFilterEntity>() {
            @Override
            public void onItemClick(PickFilterEntity pickFilterEntity, int position) {
                listener.onItemClick(pickFilterEntity);
                dismiss();
            }
        });
    }

    public interface BoxOnClickListener {
        void onItemClick(PickFilterEntity entity);
    }

    public void setListener(BoxOnClickListener listener) {
        this.listener = listener;
    }

    public void setData(List<PickFilterEntity> data) {
        adapter.setDatas(data);
    }

    public void setData(List<PickFilterEntity> data, int DefItem) {
        adapter.setDatas(data);
        //默认选中第几个
        adapter.setDefItem(DefItem);
    }
}
